package demo1;

import list.MyArrayList;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
    }
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list.add(list1);

        for(int i=1;i<numRows;i++) {
            List<Integer> list2 = new ArrayList<>();
            for(int j=0;j<=i;j++) {
                if(j==0 || j==i) {
                    list2.add(1);
                }else{
                    int val1 = list.get(i-1).get(j-1);
                    int val2 = list.get(i-1).get(j);
                    list2.add(val1+val2);
                }
            }
            list.add(list2);
        }

        return list;
    }

    public static void main3(String[] args) {
        generate(5);
    }
    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(10);
        list.add(20);
        list.add(30);
        list.add(40);
        list.add(50);
        int size = list.size();
        for (int i = 0; i < size; i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();

        for (int x: list) {
            System.out.print(x + " ");
        }
        System.out.println();
        for (Integer y: list) {
            System.out.print(y + " ");
        }
        System.out.println();


        ListIterator<Integer> it =  list.listIterator(list.size());
        while (it.hasPrevious()) {
            System.out.print(it.previous()+" ");
        }
        System.out.println();

        System.out.println(list);
    }

    public static void main1(String[] args) {
//        MyArrayList myArrayList = new MyArrayList();
//        myArrayList.add(1);
//        myArrayList.add(2);
//        int ret = myArrayList.get(3);
//        System.out.println(ret);
//        myArrayList.add(3);
//        ret = myArrayList.get(10);
//        System.out.println(ret);
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
        myArrayList.display();
        myArrayList.add(6);
        myArrayList.add(7);
        myArrayList.add(8);
        myArrayList.display();
        myArrayList.add(2,314);
        myArrayList.display();
        System.out.println(myArrayList.contains(314));
        System.out.println(myArrayList.indexOf(314));
        myArrayList.remove(314);
        myArrayList.display();
        System.out.println(myArrayList.size());
        System.out.println(myArrayList.indexOf(5));
        System.out.println(myArrayList.get(5));
        myArrayList.add(15,45);
    }
}
